Skip to content

Conversation

@alessiostalla
Copy link
Member

This PR contains a number of changes to AST transformers as listed in #417
Many of these are breaking changes that we couldn't introduce in a patch version update for Kolasu 1.5.

@alessiostalla alessiostalla marked this pull request as ready for review October 28, 2025 16:35
Copy link
Member

@ftomassetti ftomassetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have mostly cosmetic, organizational or naming comments

val source: Source? = null,
throwOnUnmappedNode: Boolean = true,
) : ASTTransformer(issues, allowGenericNode, throwOnUnmappedNode) {
faultTolerance: FaultTolerance = FaultTolerance.THROW_ONLY_ON_UNMAPPED,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

cause: Throwable? = null,
) : Exception(message, cause)

enum class ChildrenPolicy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
We may also add some javadocs for the entries

var finalizer: (Output) -> Unit = {},
var skipChildren: Boolean = false,
var childrenSetAtConstruction: Boolean = false,
class Transform<Source, Output : ASTNode>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TransformationContext is open, should all classes using it be parametric and takes a type parameter TC extending TransformationContext?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the name. The comment says it is a factory, should it be called one of these?

  • Transformation
  • Transformer
  • TransformationFactory
  • TransformerFactory
  • NodeFactory

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TransformationContext is open, should all classes using it be parametric and takes a type parameter TC extending TransformationContext?

I considered that but I didn't want to further complicate already complex/verbose type signatures. Interested parties can cast a context to the desired type.

I am not sure about the name. The comment says it is a factory, should it be called one of these?

It used to be called NodeFactory, that's why the comment still refers to it as a factory. What about TransformationRule?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but I didn't want to further complicate already complex/verbose type signatures. Interested parties can cast a context to the desired type.

Makes sense

It used to be called NodeFactory, that's why the comment still refers to it as a factory. What about TransformationRule?

Yes, I think TransformationRule is a good name

childType: KClass<out ASTNode> = ASTNode::class,
): NodeFactory<Source, Output> {
): Transform<Source, Output> {
if (childrenPolicy == ChildrenPolicy.SKIP) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the different children policy through a top-level when statement?

@alessiostalla alessiostalla merged commit 6f865c8 into main Oct 31, 2025
6 checks passed
@alessiostalla alessiostalla deleted the feature/revisited-ast-transformers branch October 31, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants